package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlTeam;
import com.ruoyi.sl.service.ISlMonthOfcService;
import com.ruoyi.sl.service.ISlVacationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlLeaveRecord;
import com.ruoyi.sl.service.ISlLeaveRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假记录Controller
 * 
 * @author admin
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/sl/leaverecord")
public class SlLeaveRecordController extends BaseController
{
    @Autowired
    private ISlLeaveRecordService slLeaveRecordService;
    @Autowired
    private ISlVacationService slVacationService;

    /**
     * 查询请假记录列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlLeaveRecord slLeaveRecord)
    {
        startPage();
        List<SlLeaveRecord> list = slLeaveRecordService.selectSlLeaveRecordList(slLeaveRecord);
        return getDataTable(list);
    }

    /**
     * 导出请假记录列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:export')")
    @Log(title = "请假记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlLeaveRecord slLeaveRecord)
    {
        List<SlLeaveRecord> list = slLeaveRecordService.selectSlLeaveRecordList(slLeaveRecord);
        ExcelUtil<SlLeaveRecord> util = new ExcelUtil<SlLeaveRecord>(SlLeaveRecord.class);
        util.exportExcel(response, list, "请假记录数据");
    }

    /**
     * 获取请假记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:query')")
    @GetMapping(value = { "/", "/{leaveRecordId}" })
    public AjaxResult getInfo(@PathVariable(value = "leaveRecordId", required = false) Long leaveRecordId)
    {
        AjaxResult ajax = new AjaxResult();
        ajax.put("vacations",slVacationService.selectVacationAll());
        if(StringUtils.isNotNull(leaveRecordId)){
            SlLeaveRecord slLeaveRecord = slLeaveRecordService.selectSlLeaveRecordByLeaveRecordId(leaveRecordId);
            ajax.put(AjaxResult.DATA_TAG, slLeaveRecord);
        }
        return ajax;
    }

    /**
     * 新增请假记录
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:add')")
    @Log(title = "请假记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlLeaveRecord slLeaveRecord)
    {
        slLeaveRecord.setCreateBy(getUsername());
        return toAjax(slLeaveRecordService.insertSlLeaveRecord(slLeaveRecord));
    }

    /**
     * 修改请假记录
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:edit')")
    @Log(title = "请假记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlLeaveRecord slLeaveRecord)
    {
        slLeaveRecord.setUpdateBy(getUsername());
        return toAjax(slLeaveRecordService.updateSlLeaveRecord(slLeaveRecord));
    }

    /**
     * 删除请假记录
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:remove')")
    @Log(title = "请假记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaveRecordIds}")
    public AjaxResult remove(@PathVariable Long[] leaveRecordIds)
    {
        return toAjax(slLeaveRecordService.deleteSlLeaveRecordByLeaveRecordIds(leaveRecordIds));
    }
}
